<?php
/**
 * Copyright (c) 2018-2019.
 *  This file is part of the moonpie production
 *  (c) johnzhang <875010341@qq.com>
 *  This source file is subject to the MIT license that is bundled
 *  with this source code in the file LICENSE.
 */

namespace moonpie\plugin\wechat_account\controller;


use app\common\service\traits\PluginControllerTrait;
use app\manager\controller\Base;
use moonpie\plugin\wechat_account\model\WechatAccount;

/**
 * 抽象控制器父类，主要是用来处理公众号后台相关操作
 * Class AbstractBackendController
 * @package moonpie\plugin\wechat_account\controller
 */
abstract class AbstractBackendController extends Base
{
    use PluginControllerTrait;
    protected $menuName = 'wechat_account';

    protected function checkCurrentAccount()
    {
        if($this->request->has('account_id')){
            $account = WechatAccount::loadById($this->request->param('account_id'));
        }else {
            $account = null;
        }
        if(!$account) $this->error('指定的公众号信息不存在');
        $this->request->bind('current_wechat_account', $account);
    }
    protected function _prepareBaseViewVars()
    {

        $this->assign([
            'extend_view' => $this->parseTemplateName('#/common/base'),
            'header_file' => $this->parseTemplateName('#/common/header'),
            'sidebar_file' => $this->parseTemplateName('#/common/menu'),
            ]);
    }

    protected function getCurrentAccount()
    {
        /** @var \moonpie\plugin\wechat_account\model\WechatAccount $account */
        $account = $this->request->current_wechat_account;
        return $account;
    }
}